package com.gksc.video.data;

import java.util.HashMap;
import java.util.Map;

/**
 * @className: JsonResponse
 * @description: 请求响应结果类
 * @author: Liao.yx
 * @email: 1229053515@qq.com
 * @create: 2020年09月24日 18时59分
 * @copyRight: 2020 liaoyongxiang All rights reserved.
 **/
public class JsonResponse extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public JsonResponse() {
        put("code", 0);
    }

    public static JsonResponse error() {
        JsonResponse r = new JsonResponse();
        Map<String, Object> data = new HashMap<>();
        data.put("code", 500);
        data.put("msg", "未知异常，请联系管理员");
        r.put("state", data);
        return r;
    }

    public static JsonResponse success() {
        JsonResponse r = new JsonResponse();
        Map<String, Object> data = new HashMap<>();
        data.put("code", 200);
        data.put("msg", "操作成功");
        r.put("state", data);
        return r;
    }

    public JsonResponse put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static JsonResponse error(String msg) {
        JsonResponse r = new JsonResponse();
        Map<String, Object> data = new HashMap<>();
        data.put("code", -1);
        data.put("msg", msg);
        r.put("state", data);
        return r;
    }

    public static JsonResponse success(Object returnData) {
        JsonResponse r = new JsonResponse();
        Map<String, Object> data = new HashMap<>();
        data.put("code", 200);
        data.put("msg", "操作成功");
        r.put("state", data);
        r.put("data", returnData);
        return r;
    }
}
